import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PushbackReader;

@WebServlet("/user")
public class UserServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf8");
        resp.setContentType("text/html; charset=utf8");
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        //非空校验
        if(username == null || username.equals("") ||
        password == null || password.equals("")) {
            resp.getWriter().write("注册用户名和密码不能为空");
            return;
        }
        UserInfo userInfo = new UserInfo();
        userInfo.setUsername(username);
        userInfo.setPassword(password);
        //将数据存储到数据库中
        UserInfoDao userInfoDao = new UserInfoDao();
        userInfoDao.insert(userInfo);
        resp.getWriter().write("注册成功");
    }
}
